package com.esteel.settlement.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.esteel.settlement.dao.SettInmoneyRepository;
import com.esteel.settlement.entity.TbSettFund;
import com.esteel.settlement.entity.TbSettInmoney;
import com.esteel.settlement.entity.TbSettTran;
import com.esteel.settlement.service.SettInmoneyService;

@Service
public class SettInmoneyServiceImpl implements SettInmoneyService{

	@Autowired
	private SettInmoneyRepository settInmoneyRepository;
	
	@Autowired
	 private JdbcTemplate jdbcTemplate;
	 
	@Override
	public TbSettInmoney save(TbSettInmoney entity) {
		return settInmoneyRepository.save(entity);

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TbSettInmoney> selectInmoney(TbSettInmoney entity) {
		// TODO Auto-generated method stub
//		String str= "2017-04-07 00:00:00";
		SimpleDateFormat SFDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strb=SFDate.format(entity.getBeginDate());//entity.getTranDate();
		String stre=SFDate.format(entity.getEndDate());//entity.getTranDate();
		List<TbSettInmoney> tb= jdbcTemplate.query("select * from TB_SETT_INMONEY t where t.acct_date>=to_date (? , 'YYYY-MM-DD HH24:MI:SS' ) and t.acct_date<=to_date (? , 'YYYY-MM-DD HH24:MI:SS' )", new Object[]{strb,stre},new RowMapper(){

			@Override
			public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
				// TODO Auto-generated method stub
				TbSettInmoney tb= new TbSettInmoney();
				tb.setInId(rs.getLong("IN_ID"));
				tb.setCcyCode(rs.getString("CCY_CODE"));
				tb.setCounterId(rs.getString("COUNTER_ID"));
				tb.setSupAcctId(rs.getString("SUP_ACCT_ID"));
				tb.setInAcctId(rs.getString("IN_ACCT_ID"));
				tb.setInAcctIdName(rs.getString("IN_ACCT_ID_NAME"));
				tb.setLogNo(rs.getString("LOG_NO"));
				tb.setTranStatus(rs.getInt("TRAN_STATUS"));
//				tb.setCustFlag(rs.getInt("CUST_FLAG"));
//				tb.setTranDate(rs.getDate("TRAN_DATE"));
				return tb;
			}	
			
		});
		System.out.println(tb.size());
		return tb;
	}

}
